package com.lin.missyou.vo;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;

/**
 * T，K 泛型 不确定的类型 传递过来的的参数
 * @author gcq
 * @Create 2021-10-15
 */
public class PagingDozer<T, K> extends Paging {

    // 取消编译警告
    @SuppressWarnings("unchecked")
    public PagingDozer(Page<T> pageT, Class<K> classK)
    {
        this.initPageParameters(pageT);

        List<T> tList = pageT.getContent();
        Mapper mapper = DozerBeanMapperBuilder.buildDefault();
        List<K> voList = new ArrayList<>();

        tList.forEach(t -> {
            K vo = mapper.map(t, classK);
            voList.add(vo);
        });
        this.setItems(voList);
    }
}